package com.modern.model;

import com.modern.model.BaseObject;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import java.io.Serializable;

@Entity
@Table(name="paper",catalog="typing")
public class Paper extends BaseObject implements Serializable {
    private Long paperId;
    private Question question;
    private Date createTime;
    private Date endTime;
    private Date startTime;
    private Set<Answer> answers = new HashSet<Answer>(0);

    @Id @GeneratedValue(strategy=IDENTITY)     
    public Long getPaperId() {
        return this.paperId;
    }
    
    public void setPaperId(Long paperId) {
        this.paperId = paperId;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="questionId")
    public Question getQuestion() {
        return this.question;
    }
    
    public void setQuestion(Question question) {
        this.question = question;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="createTime", length=0)
    public Date getCreateTime() {
        return this.createTime;
    }
    
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="endTime", length=0)
    public Date getEndTime() {
        return this.endTime;
    }
    
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="startTime", length=0)
    public Date getStartTime() {
        return this.startTime;
    }
    
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="paper")
    public Set<Answer> getAnswers() {
        return this.answers;
    }
    
    public void setAnswers(Set<Answer> answers) {
        this.answers = answers;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Paper pojo = (Paper) o;

        if (question != null ? !question.equals(pojo.question) : pojo.question != null) return false;
        if (createTime != null ? !createTime.equals(pojo.createTime) : pojo.createTime != null) return false;
        if (endTime != null ? !endTime.equals(pojo.endTime) : pojo.endTime != null) return false;
        if (startTime != null ? !startTime.equals(pojo.startTime) : pojo.startTime != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (question != null ? question.hashCode() : 0);
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (endTime != null ? endTime.hashCode() : 0);
        result = 31 * result + (startTime != null ? startTime.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("paperId").append("='").append(getPaperId()).append("', ");
        sb.append("question").append("='").append(getQuestion()).append("', ");
        sb.append("createTime").append("='").append(getCreateTime()).append("', ");
        sb.append("endTime").append("='").append(getEndTime()).append("', ");
        sb.append("startTime").append("='").append(getStartTime()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }

}
